package com.yc.springmvc;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

public class MyWebApplnit implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigApplicationContext cxt =new AnnotationConfigApplicationContext();
        cxt.register(MVCConfig.class);

        DispatcherServlet dispatchServlet = new DispatcherServlet((WebApplicationContext)cxt);
        ServletRegistration.Dynamic registration = servletContext.addServlet("app", dispatchServlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("/");
    }
}
